<?php 
/*
* 侧边栏组件、页面模块
*/
if(!defined('EMLOG_ROOT')) {exit('error!');} 
?>
<?php
//widget：blogger
function widget_blogger($title){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$name = $user_cache[1]['mail'] != '' ? "<a href=\"mailto:".$user_cache[1]['mail']."\">".$user_cache[1]['name']."</a>" : $user_cache[1]['name'];?>
    
    <!--side blogger Stard-->
            <div class="sidebox-header"></div>
            
            <div class="sidebox">
            	<ul class="sidecustom">
                
                
            
            <div class="side-title-banner fleft"  style="margin-left:10px;border: 1px dashed #C6C8CB;">
					<div id="side-box-banner">
						<img src="<?php echo BLOG_URL.$user_cache[1]['photo']['src']; ?>" width="65" height="65" alt="Blogger" />
					</div>
			</div>
            <div class="side-title-banner fleft"  style="margin-left:10px;border: 1px dashed #C6C8CB;">
					<div id="side-box-banner">
						<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=495959785&site=qq&menu=yes"><img src="<?php echo TEMPLATE_URL; ?>style/img/blue/qq.gif" width="65" height="65" alt="点击这里给我发QQ消息" title="点击这里给我发QQ消息" /></a>
				</div>
			</div>
            <div class="side-title-banner fleft" style="margin-left:10px;border: 1px dashed #C6C8CB;">
					<div id="side-box-banner">
						<a target="_blank"  href="http://t.qq.com/JonsCheng"><img src="<?php echo TEMPLATE_URL; ?>style/img/blue/qq-t.gif" width="65" height="65" alt="Jons的腾讯微博" title="点击收听我的微博" /></a>
               	 	</div>
			</div>
            <div style="clear: both;"></div>
                <?php echo $user_cache[1]['des']; ?>
				</ul>
            </div>
        	<div class="sidebox-footer"></div>
            <!--side blogger end-->
            
    
    
    
    
    
    

<?php }?>
<?php
//widget：日历
function widget_calendar($title){ ?>

<!--side calendar Stard-->
	        <div class="side-title-holder">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon date_ico"></span><?php echo $title; ?></div>
				</div>
			</div>
            
            
            <div class="sidebox">
                 <ul class="sidecustom">
                 
                 <div id="calendar">
	</div>
	<script>sendinfo('<?php echo Calendar::url(); ?>','calendar');</script>
	
                 </ul>
            </div>
            <div class="sidebox-footer"></div>
           <!--side calendar end-->



	
<?php }?>
<?php
//widget：标签
function widget_tag($title){
	global $CACHE;
	$tag_cache = $CACHE->readCache('tags');?>
    
    <!--side custom Stard-->
        	<div class="side-title-holder sidebox">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon custom_ico"></span><?php echo $title; ?></div>
				</div>
			</div>
            <div class="sidebox">
            	<ul class="sidecustom">   
	<?php shuffle($tag_cache);
     $tag_cache = array_slice($tag_cache,0,40);
	 foreach($tag_cache as $value):?>
		<a class="sidetag" href="<?php echo Url::tag($value['tagurl']); ?>" title="<?php echo $value['usenum']; ?> 篇日志"><?php echo $value['tagname']; ?></a>

	<?php endforeach; ?>
 </ul>
            </div>        
        	<div class="sidebox-footer"></div>   
           <!--side custom end-->
    
    
    
<?php }?>
<?php
//widget：分类
function widget_sort($title){
	global $CACHE;
	$sort_cache = $CACHE->readCache('sort'); ?><div class="sidebox-header"></div>
            <!--side sort Stard-->
        	<ul class="sidemenu sidebox">
<?php foreach($sort_cache as $value): ?>
				<li><a href="<?php echo Url::sort($value['sid']); ?>"><span class="aside-icon sort-icon"></span><span class="sidemenu-item-number"><?php echo $value['lognum'] ?></span><?php echo $value['sortname']; ?></a></li>
	<?php endforeach; ?>
			</ul>
            <div class="sidebox-footer"></div>
            <!--side sort end--> 
<?php }?>
<?php
//widget：最新碎语
function widget_twitter($title){
	global $CACHE; 
	$newtws_cache = $CACHE->readCache('newtw');
	$istwitter = Option::get('istwitter');
	?>
               <!--side TW Stard-->
        	<div class="side-title-holder sidebox">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon t_ico"></span><?php echo $title; ?></div>
				</div>
			</div>

            <div class="sidebox">
                <ul class="sidetw">
	<?php foreach($newtws_cache as $value): ?>
	<?php $img = empty($value['img']) ? "" : '<a title="查看图片" class="t_img" href="'.BLOG_URL.str_replace('thum-', '', $value['img']).'" target="_blank">&nbsp;</a>';?>
    
    <li><?php echo smartDate($value['date']); ?><p> <?php echo $img;?><?php echo $value['t']; ?></p></li>
	<?php endforeach; ?>

				</ul>
            </div>
			<div class="sidebox-footer"></div>
           <!--side TW end-->
<?php }?>
<?php
//widget：最新评论
function widget_newcomm($title){
	global $CACHE; 
	$com_cache = $CACHE->readCache('comment');
	?>
    
               <!--side comment Stard-->
        	<div class="side-title-holder sidebox">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon com_ico"></span><?php echo $title; ?></div>
				</div>
			</div>
            
            <div class="sidebox">
                <ul class="sidecom">
	<?php
	foreach($com_cache as $value):
	$url = Url::comment($value['gid'], $value['page'], $value['cid']);
	?>
    <li><?php echo $value['name']; ?><p><a href="<?php echo $url; ?>"><?php echo $value['content']; ?></a></p></li>
    
	<?php endforeach; ?>
				</ul>
            </div>
			<div class="sidebox-footer"></div>
           <!--side comment end-->
<?php }?>
<?php
//widget：最新日志
function widget_newlog($title){
	global $CACHE; 
	$newLogs_cache = $CACHE->readCache('newlog');
	?>
     <!--side Nowlog Stard-->
        	<div class="side-title-holder">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon list_ico"></span><?php echo $title; ?></div>
				</div>
			</div>
            
            <div class="sidebox">
                <ul class="sidelist">
	<?php foreach($newLogs_cache as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
            </div>
			<div class="sidebox-footer"></div>
       	   <!--side Nowlog end-->
<?php }?>
<?php
//widget：热门日志
function widget_hotlog($title){
	$index_hotlognum = Option::get('index_hotlognum');
	$Log_Model = new Log_Model();
	$randLogs = $Log_Model->getHotLog($index_hotlognum);?>
         <!--side Hotlog Stard-->
        	<div class="side-title-holder">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon list_ico"></span><?php echo $title; ?></div>
				</div>
			</div>
            
            <div class="sidebox">
                <ul class="sidelist">
	<?php foreach($randLogs as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
            </div>
			<div class="sidebox-footer"></div>
       	   <!--side Hotlog end-->
<?php }?>
<?php
//widget：随机日志
function widget_random_log($title){
	$index_randlognum = Option::get('index_randlognum');
	$Log_Model = new Log_Model();
	$randLogs = $Log_Model->getRandLog($index_randlognum);?>
         <!--side Hotlog Stard-->
        	<div class="side-title-holder">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon list_ico"></span><?php echo $title; ?></div>
				</div>
			</div>
            
            <div class="sidebox">
                <ul class="sidelist">
	<?php foreach($randLogs as $value): ?>
	<li><a href="<?php echo Url::log($value['gid']); ?>"><?php echo $value['title']; ?></a></li>
	<?php endforeach; ?>
	</ul>
            </div>
			<div class="sidebox-footer"></div>
       	   <!--side Hotlog end-->
<?php }?>
<?php
//widget：搜索
function widget_search($title){ ?>

<!--side custom Stard-->
        	<div class="sidebox-header"></div>
            <div class="sidebox">
            	<ul class="sidecustom">   
	
	<form name="keyform" method="get" action="<?php echo BLOG_URL; ?>index.php">
	<input type="text" class="search" autocomplete="off" value='输入后按回车搜索...' onblur="if(this.value == '')this.value='输入后按回车搜索...'" onfocus="if(this.value == '输入后按回车搜索...')this.value = ''"  name="keyword" >
					
					<button class="search-submit" type="submit"></button>
	</form>
	
 </ul>
            </div>        
        	<div class="sidebox-footer"></div>   
           <!--side custom end-->


<?php } ?>
<?php
//widget：归档
function widget_archive($title){
	global $CACHE; 
	$record_cache = $CACHE->readCache('record');
	?>
    <div class="sidebox-header"></div>
            <!--side sort Stard-->
        	<ul class="sidemenu sidebox">
<?php foreach($record_cache as $value): ?>
				<li><a href="<?php echo Url::record($value['date']); ?>"><span class="aside-icon sort-icon"></span><span class="sidemenu-item-number"><?php echo $value['lognum']; ?></span><?php echo $value['record']; ?></a></li>
	<?php endforeach; ?>
			</ul>
            <div class="sidebox-footer"></div>
            <!--side sort end--> 
    
    
    
<?php } ?>
<?php
//widget：自定义组件
function widget_custom_text($title, $content){ ?>
            <!--side custom Stard-->
        	<div class="side-title-holder sidebox">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon custom_ico"></span><?php echo $title; ?></div>
				</div>
			</div>
            <div class="sidebox">
            	<ul class="sidecustom">   
	<?php echo $content; ?>
 </ul>
            </div>        
        	<div class="sidebox-footer"></div>   
           <!--side custom end-->
<?php } ?>
<?php
//widget：链接
function widget_link($title){
	global $CACHE; 
	$link_cache = $CACHE->readCache('link');
	?>
    
     <!--side link Stard-->
        	<div class="side-title-holder sidebox">
				<div class="side-title-box">
					<div id="side-box-title"><span class="aside-icon link_ico"></span><?php echo $title; ?></div>
				</div>
			</div>

            <div class="sidebox">
                <div class="link">
                   <ul><?php foreach($link_cache as $value): ?>
				  	  <li><a href="<?php echo $value['url']; ?>" title="<?php echo $value['des']; ?>" target="_blank"><?php echo $value['link']; ?></a></li>
	               <?php endforeach; ?></ul>
                   <div style="width:200px;clear: both;"></div>
                </div>
            </div>
        	<div class="sidebox-footer"></div>
           <!--side link end-->
    
    
    
    
    
    
   
<?php }?>
<?php
//blog：导航
function blog_navi(){
	global $CACHE; 
	$navi_cache = $CACHE->readCache('navi');
	?>
	<ul>
	<?php 
	foreach($navi_cache as $value):
		if($value['url'] == 'admin' && (ROLE == 'admin' || ROLE == 'writer')):
			?>
			<li class="common"><a href="<?php echo BLOG_URL; ?>admin/write_log.php">写日志</a></li>
			<li class="common"><a href="<?php echo BLOG_URL; ?>admin/">管理站点</a></li>
			<li class="common"><a href="<?php echo BLOG_URL; ?>admin/?action=logout">退出</a></li>
			<?php 
			continue;
		endif;
		$newtab = $value['newtab'] == 'y' ? 'target="_blank"' : '';
		$value['url'] = $value['isdefault'] == 'y' ? BLOG_URL . $value['url'] : trim($value['url'], '/');
		$current_tab = (BLOG_URL . trim(Dispatcher::setPath(), '/') == $value['url']) ? 'current' : 'common';
		?>
		<li class="<?php echo $current_tab;?>"><a href="<?php echo $value['url']; ?>" <?php echo $newtab;?>><?php echo $value['naviname']; ?></a></li>
	<?php endforeach; ?>
	</ul>
<?php }?>
<?php
//blog：置顶
function topflg($istop){
	$topflg = $istop == 'y' ? "<span class=\"aside-icon zd_ico\"></span> " : '';
	echo $topflg;
}
?>
<?php
//blog：编辑
function editflg($logid,$author){
	$editflg = ROLE == 'admin' || $author == UID ? '<a href="'.BLOG_URL.'admin/write_log.php?action=edit&gid='.$logid.'" target="_blank">编辑</a>' : '';
	echo $editflg;
}
?>
<?php
//blog：分类
function blog_sort($blogid){
	global $CACHE; 
	$log_cache_sort = $CACHE->readCache('logsort');
	?>
	<?php if(!empty($log_cache_sort[$blogid])): ?>
	<a class="fleft" href="<?php echo Url::sort($log_cache_sort[$blogid]['id']); ?>"><?php echo $log_cache_sort[$blogid]['name']; ?></a>
	<?php endif;?>
<?php }?>
<?php
//blog：日志标签
function blog_tag($blogid){
	global $CACHE;
	$log_cache_tags = $CACHE->readCache('logtags');
	if (!empty($log_cache_tags[$blogid])){
		$tag = '';
		foreach ($log_cache_tags[$blogid] as $value){
			$tag .= "	<a href=\"".Url::tag($value['tagurl'])."\">".$value['tagname'].'</a>';
		}
		echo $tag;
	}
}
?>
<?php
//blog：日志作者
function blog_author($uid){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$author = $user_cache[$uid]['name'];
	$mail = $user_cache[$uid]['mail'];
	$des = $user_cache[$uid]['des'];
	$title = !empty($mail) || !empty($des) ? "title=\"$des $mail\"" : '';
	echo '<a href="'.Url::author($uid)."\" $title>$author</a>";
}
?>
<?php
//blog：相邻日志
function neighbor_log($neighborLog){
	extract($neighborLog);?>
	<?php if($prevLog):?><a class="prevLog fleft" href="<?php echo Url::log($prevLog['gid']) ?>">上一篇：<?php echo $prevLog['title'];?></a>
	<?php endif;?>
	<?php if($nextLog && $prevLog):?>
                                
                                
	<?php endif;?>
	<?php if($nextLog):?>
		<a class="nextLog fright" href="<?php echo Url::log($nextLog['gid']) ?>">
                                     下一篇：<?php echo $nextLog['title'];?>
                                </a>
	<?php endif;?>
<?php }?>
<?php
//blog：引用通告
function blog_trackback($tb, $tb_url, $allow_tb){
    if($allow_tb == 'y' && Option::get('istrackback') == 'y'):?>
	<div id="trackback_address">
	<p>引用地址: <input type="text" style="width:350px" class="input" value="<?php echo $tb_url; ?>">
	<a name="tb"></a></p>
	</div>
	<?php endif; ?>
	<?php foreach($tb as $key=>$value):?>
		<ul id="trackback">
		<li><a href="<?php echo $value['url'];?>" target="_blank"><?php echo $value['title'];?></a></li>
		<li>BLOG: <?php echo $value['blog_name'];?></li><li><?php echo $value['date'];?></li>
		</ul>
	<?php endforeach; ?>
<?php }?>
<?php
//blog：博客评论列表
function blog_comments($comments){
    extract($comments);
    if($commentStacks): $commnum = count($comments);?>
    <div class="meta" style="border-bottom:1px solid #ECEEF0;"></div>
	<a name="comments"></a>
	<p class="comment-header"><b>评论(<?php echo $commnum; ?>)条</b></p>
	<?php endif; ?>
		<?php
	$isGravatar = Option::get('isgravatar');
	foreach($commentStacks as $cid):
    $comment = $comments[$cid];
	$comment['poster'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank">'.$comment['poster'].'</a>' : $comment['poster'];
	?>
	<div class="comment" id="comment-<?php echo $comment['cid']; ?>">
		<a name="<?php echo $comment['cid']; ?>"></a>
		<?php if($isGravatar == 'y'): ?><div class="avatar"><img src="<?php echo getGravatar($comment['mail']); ?>" /></div><?php endif; ?>
		<span class="comment-name"><?php echo $comment['poster']; ?> </span><br /><span class="comment-time"><?php echo $comment['date']; ?></span>
		<div class="comment-info">
			<div class="comment-content"><?php echo $comment['content']; ?></div>
			<div class="comment-reply"><a href="#comment-<?php echo $comment['cid']; ?>" onclick="commentReply(<?php echo $comment['cid']; ?>,this)" style="color:#959594">回复</a></div>
		</div>
		<?php blog_comments_children($comments, $comment['children']); ?>
	</div>
	<?php endforeach; ?>
    <div id="pagenavi">
	    <?php echo $commentPageUrl;?>
    </div>
<?php }?>
<?php
//blog：博客子评论列表
function blog_comments_children($comments, $children){
	$isGravatar = Option::get('isgravatar');
	foreach($children as $child):
	$comment = $comments[$child];
	$comment['poster'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank">'.$comment['poster'].'</a>' : $comment['poster'];
	?>
	<div class="comment comment-children" id="comment-<?php echo $comment['cid']; ?>">
		<a name="<?php echo $comment['cid']; ?>"></a>
		<?php if($isGravatar == 'y'): ?><div class="avatar"><img src="<?php echo getGravatar($comment['mail']); ?>" /></div><?php endif; ?>
		<b style="color:#AEB468"><?php echo $comment['poster']; ?> </b><br /><span class="comment-time"><?php echo $comment['date']; ?></span>
		<div class="comment-info">
			<div class="comment-content"><?php echo $comment['content']; ?></div>
			<?php if($comment['level'] < 4): ?><div class="comment-reply"><a href="#comment-<?php echo $comment['cid']; ?>" onclick="commentReply(<?php echo $comment['cid']; ?>,this)" style="color:#959594">回复</a></div><?php endif; ?>
		</div>
		<?php blog_comments_children($comments, $comment['children']);?>
	</div>
	<?php endforeach; ?>
<?php }?>
<?php
//blog：发表评论表单
function blog_comments_post($logid,$ckname,$ckmail,$ckurl,$verifyCode,$allow_remark){
	if($allow_remark == 'y'): ?>
	<div id="comment-place">
	<div class="comment-post" id="comment-post">
		<div class="cancel-reply" id="cancel-reply" style="display:none"><a href="javascript:void(0);" onclick="cancelReply()">取消回复</a></div>
		<p class="comment-header"><b></b><a name="respond"></a></p>
		<form method="post" name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform">
			<input type="hidden" name="gid" value="<?php echo $logid; ?>" />
			<?php if(ROLE == 'visitor'): ?>
			<p>
				<input type="text" name="comname" maxlength="49" value="<?php echo $ckname; ?>" size="22" tabindex="1">
				<label for="author"><small>昵称（必填）***</small></label>
			</p>
			<p>
				<input type="text" name="commail"  maxlength="128"  value="<?php echo $ckmail; ?>" size="22" tabindex="2">
				<label for="email"><small>邮箱（选填，填写后您会收到我的邮件回复哦！）</small></label>
			</p>
			<p>
				<input type="text" name="comurl" maxlength="128"  value="<?php echo $ckurl; ?>" size="22" tabindex="3">
				<label for="url"><small>网址（选填，填写后本人会对您的网站回访哦！）</small></label>
			</p>
			<?php endif; ?>
			<p><textarea name="comment" id="comment" rows="10" tabindex="4"></textarea></p>
			<p><?php echo $verifyCode; ?> <input type="submit" id="comment_submit" value="提交评论" tabindex="6" /></p>
			<input type="hidden" name="pid" id="comment-pid" value="0" size="22" tabindex="1"/>
		</form>
	</div>
	</div>
	<?php endif; ?>
<?php }?>
<?php
//在列表页获取当前分类
function get_cat($sortid){
			$db = MySql::getInstance();
			$sql = "SELECT sortname FROM ".DB_PREFIX."sort WHERE sid=".$sortid;
			$s = $db->query($sql);
			$sortname = $db->fetch_array($s);
			echo '<a href="'.Url::sort($sortid).'">'.$sortname['sortname'].'</a>';
		}
?>
